package com.qiaofang.collectmanage.service.impl;

import com.qiaofang.collectmanage.base.configuration.SecretaryManageConfiguration;
import com.qiaofang.collectmanage.dao.SecretaryDao;
import com.qiaofang.collectmanage.service.SecretaryService;
import com.qiaofang.collectmanage.stub.request.SecretaryRequest;
import net.logstash.logback.encoder.org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author jingfa.sun
 */
@Service
public class SecretaryServiceImpl implements SecretaryService {

    @Autowired
    SecretaryDao secretaryDao;
    @Autowired
    private SecretaryManageConfiguration secretaryManageConfiguration;

    public SecretaryServiceImpl(SecretaryManageConfiguration secretaryManageConfiguration) {
        this.secretaryManageConfiguration = secretaryManageConfiguration;
    }

    @Override
    public void crawlerSecretaryHouseInfo(SecretaryRequest secretaryRequest){
        String loginName = secretaryManageConfiguration.getLoginName();
        String loginPass = secretaryManageConfiguration.getLoginPass();
        String loginUrl = secretaryManageConfiguration.getLoginUrl();
        String detailUrl = secretaryManageConfiguration.getDetailUrl();
        String detailParam = secretaryManageConfiguration.getDetailParam();
        String pageCharset = secretaryManageConfiguration.getPageCharset();
        String defaultPage = StringUtils.isNotBlank(secretaryRequest.getDefaultPage())?secretaryRequest.getDefaultPage():secretaryManageConfiguration.getDefaultPage();
        String beeTable = secretaryManageConfiguration.getBeeTable();
        String beeType = secretaryManageConfiguration.getBeeType();
        String waitTime = secretaryManageConfiguration.getWaitTime();
        secretaryRequest.setLoginName(loginName);
        secretaryRequest.setLoginPass(loginPass);
        secretaryRequest.setLoginUrl(loginUrl);
        secretaryRequest.setDetailUrl(detailUrl);
        secretaryRequest.setDetailParam(detailParam);
        secretaryRequest.setPageCharset(pageCharset);
        secretaryRequest.setDefaultPage(defaultPage);
        secretaryRequest.setBeeTable(beeTable);
        secretaryRequest.setBeeType(beeType);
        secretaryRequest.setWaitTime(waitTime);
       secretaryDao.crawlerSecretaryHouseInfo(secretaryRequest);
    }

}
